<?php

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

class CreateBusinessType extends AbstractMigration
{
    public function change()
    {
        $table = $this->table('business_type', ['id' => true]);
        $table->addColumn('code', 'string', ['limit' => 50, 'comment' => '类型编码'])
            ->addColumn('name', 'string', ['limit' => 100, 'comment' => '类型名称'])
            ->addColumn('icon', 'string', ['limit' => 100, 'null' => true, 'comment' => '图标'])
            ->addColumn('description', 'string', ['limit' => 255, 'null' => true, 'comment' => '描述'])
            ->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'default' => 1, 'comment' => '状态：0=禁用,1=启用'])
            ->addColumn('sort', 'integer', ['default' => 0, 'comment' => '排序'])
            ->addColumn('created_at', 'datetime', ['null' => true, 'comment' => '创建时间'])
            ->addColumn('updated_at', 'datetime', ['null' => true, 'comment' => '更新时间'])
            ->addIndex(['code'], ['unique' => true])
            ->addIndex(['status'])
            ->create();

        // 添加默认数据
        $rows = [
            [
                'code' => 'scenic',
                'name' => '景区',
                'status' => 1,
                'sort' => 1,
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s')
            ],
            [
                'code' => 'hotel',
                'name' => '酒店',
                'status' => 1,
                'sort' => 2,
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s')
            ],
            [
                'code' => 'restaurant',
                'name' => '餐饮',
                'status' => 1,
                'sort' => 3,
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s')
            ],
            [
                'code' => 'shopping',
                'name' => '购物',
                'status' => 1,
                'sort' => 4,
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s')
            ]
        ];
        $this->table('business_type')->insert($rows)->save();
    }
} 